"""
遥测数据 请求&响应 Schema
与数据库模型解耦，方便后期接口字段裁剪。
"""

from datetime import datetime
from decimal import Decimal
from typing import Optional

from pydantic import BaseModel, Field

from common.response import PaginatedResponse


# ==================== 请求 ====================
class TelemetryListRequest(BaseModel):
	"""列表查询**请求**参数（带分页）"""
	meter_code: Optional[str] = Field(None, max_length=24, description="电表编号")
	start_time: Optional[datetime] = Field(None, description="开始时间（含）")
	end_time: Optional[datetime] = Field(None, description="结束时间（含）")
	quality: Optional[str] = Field(None, description="数据质量：GOOD / BAD")
	serial_no: Optional[str] = Field(None, description="设备序列号")
	is_init: str = Field('N', description="是否初始化查询 N:非初始化，Y:初始化")


# ==================== 响应 ====================
class MeterTelemetryItem(BaseModel):
	"""单条遥测**响应**（精简字段，避免吐出敏感/冗余数据）"""
	id: int
	meter_code: str
	ts: datetime
	voltage: Optional[Decimal]
	current: Optional[Decimal]
	watt: Optional[Decimal]
	total_kwh: Optional[Decimal]
	temperature1: Optional[Decimal]
	temperature2: Optional[Decimal]
	quality: str
	created_at: datetime

	class Config:
		from_attributes = True


# 分页响应泛型实例
TelemetryListResponse = PaginatedResponse[MeterTelemetryItem]
